package com.io.example.demoparent.tree;

// 创建heroNode节点
class HeroNode{
    //
    private int no;
    // 名称
    private  String name;
    // 左边节点
    private HeroNode left;
    // 右边接节点
    private HeroNode right;

    public HeroNode(int no, String name) {
        this.no = no;
        this.name = name;

    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public HeroNode getLeft() {
        return left;
    }

    public void setLeft(HeroNode left) {
        this.left = left;
    }

    public HeroNode getRight() {
        return right;
    }

    public void setRight(HeroNode right) {
        this.right = right;
    }

    @Override
    public String toString() {
        return "HeroNode{" +
                "no=" + no +
                ", name='" + name + '\'' +
                '}';
    }

    //前序遍历
    public void preOrder(){
        System.out.println(this); //先输出父节点
        //递归向左子树遍历
        if (this.left!=null){
            this.left.preOrder();
        }
        //递归向右子节点遍历
        if (this.right!=null){
            this.right.preOrder();
        }
    }
    //中序遍历
    public void infixOrder(){

        if (this.left!=null){
            this.left.infixOrder();
        }
        System.out.println(this); //先输出父节点
        //递归向右子节点遍历
        if (this.right!=null){
            this.right.preOrder();
        }
    }
    //后序遍历

    public void PostxOrder(){

        if (this.left!=null){
            this.left.PostxOrder();
        }
        //递归向右子节点遍历
        if (this.right!=null){
            this.right.PostxOrder();
        }
        System.out.println(this); //先输出父节点
    }

}
